package com.service;

import com.dao.GoodsDAO;
import com.dao.SeckillgoodsDAO;
import com.pojo.Goods;
import com.pojo.Seckillgoods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Service
@Transactional
public class GoodsService {

    @Autowired
    private GoodsDAO goodsDAO;

    @Autowired
    private SeckillgoodsDAO seckillgoodsDAO;

    /**
     * 新增商品
     * @param goods
     */
    public void  addGoods(Goods goods)
    {
        goodsDAO.save(goods);
    }

    /*
        查所有商品
     */
    public List findAll()
    {
        List list = goodsDAO.findAll();
        return list;
    }


    /**
     * 设置商品为秒杀商品
     * @param gid
     * @param kuchun
     * @param beginTime
     */
    public void saveSeckillGoods(Long gid, Integer kuchun, String beginTime, BigDecimal price) {
        Seckillgoods  seckillgoods = new Seckillgoods();
        seckillgoods.setGoodsId(gid);
        seckillgoods.setKuchun(kuchun.longValue());
        seckillgoods.setBeginTime(java.sql.Timestamp.valueOf(beginTime));
        seckillgoods.setPrice(price);
        seckillgoodsDAO.save(seckillgoods);

    }
}
